<?php
    cria_variaveis($_POST,$_GET,$_FILES); 
?>
<p class="titulo" align="center"><?php echo $msg->get('LAGRANGE_MSG_02') ?></p>
<p class="subtitulo" align="center"><?php echo $msg->get('LAGRANGE_MSG_03') ?></p>
<div class="tabbar">
    <ul>
    <li><a href="index.php?inc=lagrange.php&modo=material"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "material") echo " class=\"tabact\""; ?>><?php echo $msg->get('Material_Teorico') ?></a></li>
    <li><a href="index.php?inc=lagrange.php&modo=exemplo"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo") echo " class=\"tabact\""; ?>><?php echo $msg->get('Exemplos_Prontos') ?></a></li>
    <li><a href="index.php?inc=lagrange.php&modo=teclado"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "teclado") echo " class=\"tabact\""; ?>><?php echo $msg->get('Entrada_Teclado') ?></a></li>
    </ul>
</div>
<div id="cas">
<?php
if (!isset($Calcular)) {
    if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "material")
    {
        require_once("./classes/upload.php");
        $uploads = new Upload();
        $uploads->Lista("interpolacao");
    }
    else if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo" && !isset($opcao_execucao)) { //leitura de dados via banco de dados - modulo de exemplos e exercicios
        include "exibe_prob_lagrange_xml.php";
    }
    else if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "teclado" || isset($opcao_execucao)) {
        if(!isset($opcao_execucao))
        {
            if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo")
                verificaBib($xml_file);
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=lagrange.php>";
            echo "<br>";
            echo "".$msg->get('LAGRANGE_MSG_04')."<br><br>";
            echo "<input type=radio name=opcao_execucao value=0>".$msg->get('LAGRANGE_MSG_05')."<br>"; // 0 para caso discreto, 1 para caso continuo
            echo "<input type=radio name=opcao_execucao value=1>".$msg->get('LAGRANGE_MSG_06')."<br><br>";
            echo "<input type=hidden name=executar value=sim>";
            echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_02').">";
            echo "</form>"; 
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=lagrange.php>";
            echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
            echo "</form>";
        }
        else if ((!isset($n) && !isset($funcao) && !isset($a) && !isset($b)) || !checaNumerico($n) || ($opcao_execucao == 1 && (!checaNumerico($a) || !checaNumerico($b))))
        {
            if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo")
                verificaBib($xml_file);
?>
            <form method="post" enctype="multipart/form-data" action="index.php?inc=lagrange.php">
            <p><?php echo $msg->get('LAGRANGE_MSG_07') ?></p>
            <p><input type="text" size="3" maxlength="5" name="n"></p>
<?php
            if ($opcao_execucao==1) {
?>
            <p><a href="javascript:winopen('ajuda/funcoesphp.php')"><?php echo $msg->get('G_MSG_29') ?></a></p>	
            <p><?php echo $msg->get('LAGRANGE_MSG_09') ?></p>
            <p>f(x)= <input type="text" size="60" maxlength="100" name="funcao" value="<?php echo $funcao ?>"></p>
            <p><?php echo $msg->get('LAGRANGE_MSG_10') ?></p>
            <p>[<input type="text" size="5" maxlength="5" name="a">,<input type="text" size="5" maxlength="5" name="b">]</p>
<?php
            }// end if
?>
            <input type="hidden" name="opcao_execucao" value="<?php echo ($opcao_execucao) ?>">
            <input type="hidden" name="executar" value="sim">
            <input class="button" type="submit" name="Submit" value="<?php echo $msg->get('G_MSG_02') ?>">
            </form>
            <form method="post" enctype="multipart/form-data" action="index.php?inc=lagrange.php">
            <input class="button" type="submit" name="Submit" value="<?php echo $msg->get('G_MSG_03') ?>">
            </form>
<?php
        }
        else if ($opcao_execucao==1 && !isset($distribuicao))
        {
            if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo")
                verificaBib($xml_file);
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=lagrange.php>";
            echo "<br>";
            echo "".$msg->get('LAGRANGE_MSG_11')."".($n)."".$msg->get('LAGRANGE_MSG_12')." [&nbsp<input type=text size='4' maxlength='5' name=a value=".($a).">&nbsp,";
            echo "&nbsp<input type=text size='4' maxlength='5' name=b value=".($b).">&nbsp] :";
            echo "<input type=hidden size='4' maxlength='5' name=n value=".($n).">";
            echo "<br> <br>";
            echo "<input type=radio name=distribuicao value=1 unchecked> ".$msg->get('LAGRANGE_MSG_13')." <br>";
            echo "<input type=radio name=distribuicao value=2 unchecked> ".$msg->get('LAGRANGE_MSG_14')." <a href=\"javascript:void(0)\" onClick=\"window.open('info.php?topico=chebyshev', 'Informacoes', 'toolbar=no, location=no, directories=no, scrollbars=yes,resizable=yes,menubar=no,width=400,height=300')\"><img src=\"imagens/info.gif\" border=\"0\"></a><br>";
            echo "<br>";
            echo "<input type=hidden name=opcao_execucao value=".($opcao_execucao)." readonly>";
            echo "<input type=hidden name=n value=".($n).">";
            echo "<input type=hidden name=funcao value=\"".($funcao)."\">";
            echo "<input type=hidden name=a value=".($a).">";
            echo "<input type=hidden name=b value=".($b).">";
            echo "<input type=hidden name=executar value=sim>";
            echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_02').">";
            echo "</form>"; 
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=lagrange.php>";
            echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
            echo "</form>";
        }
        else
        { // Pagina final, para a entrada dos valores de x e y que necessitem ser digitados
            if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo")
                verificaBib($xml_file);
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=lagrange.php>";
            echo "<input type=hidden name=opcao_execucao value=".($opcao_execucao).">";
            echo "<input type=hidden name=distribuicao value=".(@$distribuicao).">";
            echo "<input type=hidden name=funcao value=\"".(@$funcao)."\">";
            //echo LAGRANGE_MSG_15;
            echo "<input type=hidden name=n value=".($n).">";
            echo "<br> <br>";
            $grau = $n-1;
            $ne=3*$grau;
            echo $msg->get('LAGRANGE_MSG_16')." <b> </b> <input type=text size='4' maxlength='5' name=grau value=".($grau).">";
            if ($opcao_execucao ==1)
            {
                echo "<br><br>".$msg->get('LAGRANGE_MSG_17')."<br>";
                echo "f(x)= ".$funcao;
            }
            if ( ($opcao_execucao == 1) && ($distribuicao==1) )
            { // distribuicao uniforme 
                echo "<br> <br>";
                //echo "".(LAGRANGE_MSG_18)." [&nbsp<input type=text size='4' maxlength='5' name=a value=".($a).">&nbsp,";
                //echo "&nbsp<input type=text size='4' maxlength='5' name=b value=".($b).">&nbsp] :";
                echo $msg->get('LAGRANGE_MSG_18')." [ $a , $b ]:";
                echo "<input type=\"hidden\" name=\"a\" value=\"$a\">";
                echo "<input type=\"hidden\" name=\"b\" value=\"$b\">";
                $fracao = ($b - $a) / ($n - 1);
                eval ('$X[0]=$a;$x=$X[0];$Y[0]='.normaliza_funcao($funcao).';');
                for ($i = 1; $i < $n; $i++) {
                    eval ('$X[$i]=$X[$i-1]+$fracao;$x=$X[$i];$Y[$i]='.normaliza_funcao($funcao).';');
                } // end for
            } // end if
            else if ( ($opcao_execucao == 1) && ($distribuicao==2) )
            { // distribuicao de chebyshev
                echo "<br> <br>";
                //echo "".(LAGRANGE_MSG_18)." [&nbsp<input type=text size='4' maxlength='5' name=a value=".($a).">&nbsp,";
                //echo "&nbsp<input type=text size='4' maxlength='5' name=b value=".($b).">&nbsp] :";
                echo $msg->get('LAGRANGE_MSG_18')." [ $a , $b ]:";
                echo "<input type=\"hidden\" name=\"a\" value=\"$a\">";
                echo "<input type=\"hidden\" name=\"b\" value=\"$b\">";
                echo "<br><br>".$msg->get('LAGRANGE_MSG_24')."<br><br>";
                echo G_FORMULA_CHEBYSHEV."";
                for ($i = 0; $i < $n; $i++) {
                    $X[$i] = ( ($a + $b)/2 ) +( ($a - $b)/2 ) * cos (((2*($i+1)-1) / (2*$n) ) * M_PI);
                    eval ('$x=$X[$i];$Y[$i]='.normaliza_funcao($funcao).';');
                } // end for
                for ($tam=$n; $tam>1; $tam--){ //ordenacao do vetor
                    for ($i=0; $i<$tam-1; $i++) {
                        if ( $X[$i] > $X[$i+1] ) {
                            $aux = $X[$i];
                            $X[$i] = $X[$i+1];
                            $X[$i+1] = $aux;
                            $aux = $Y[$i];
                            $Y[$i] = $Y[$i+1];
                            $Y[$i+1] = $aux;
                        } //end if
                    } //end for j
                } // end for i
            } // end else
            echo "<br><br>".$msg->get('LAGRANGE_MSG_19')."<br><br>";
            for ($i=0; $i<$n; $i++) {
                echo "x".$i." = <input type=text size='6' maxlength='30' name=X[".($i)."] value=".($X[$i]).">";
                echo " y".$i." = <input type=text size='6' maxlength='30' name=Y[".($i)."] value=".($Y[$i])."><br>";
            } //for
            echo "<br>";
            echo "".$msg->get('LAGRANGE_MSG_20')."<input type=text size='6' maxlength='8' name=valor value=".(@$valor).">";
            echo "<p><p>";
            echo "<p>";
            if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim")
            {
                echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
                echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">";
                echo "<input type=\"hidden\" name=\"navegacao\" value=\"sim\">";
            }
            echo "<input class=button type=submit name=Calcular value=".$msg->get('G_MSG_04').">";
            echo "<br>";
            echo "</form>";
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=lagrange.php>";
            echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
            echo "</form>";
            if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim")
            {
                echo "<form name=\"exemplos\" enctype=\"multipart/form-data\" method=\"post\">";
                echo "<script language=\"javascript\" type=\"text/javascript\">\n";
                echo "function criarLinks(value) {\n";
                echo "document.exemplos.indice.value = value;\n";
                echo "document.exemplos.action = 'index.php?inc=lagrange.php&modo=exemplo'\n";
                echo "document.exemplos.submit();\n";
                echo "}\n";
                echo "</script>";
                echo "<input type=\"hidden\" name=\"id_bib\" value=\"".@$id_bib."\">";
                echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
                echo "<input type=\"hidden\" name=\"indice\">";
                echo "</form>";
                echo $msg->get('Outros_Exemplos')."<br>";
                $objeto = new DomDocument();
                $objeto->load($xml_file);
                $filho = $objeto->getelementsbytagname("interpolation");
                if ($filho->length > 0)
                {
                    $interpol = $filho->item(0)->getelementsbytagname("interpol");
                    for ($i=0; $i<$interpol->length; $i++)
                    {
                        if ($i != 0) echo " | ";
                        if ($i == $indice) echo "<b>";
                        echo "<a href=\"javascript:criarLinks($i);\"><u>".($i+1)."</u></a>";
                        if ($i == $indice) echo "</b>";
                    }
                }
            }
        } //end if
    }
} else {
    if (!checaNumerico($X) || !checaNumerico($Y) || !checaNumerico($valor))
    {
?>
        <p><font color="red"><?php echo $msg->get('Apenas_Dados_Numericos') ?></font></p>
        <p><input type="button" value="<?php echo $msg->get('Voltar') ?>" onclick="history.back()" class="button"></p>
<?php
    }
    else
    {
        for ($tam=$n; $tam>1; $tam--)
        {
            for ($i=0; $i<$tam-1; $i++)
            {
                if ( $X[$i] > $X[$i+1] )
                {
                    $aux = $X[$i];
                    $X[$i] = $X[$i+1];
                    $X[$i+1] = $aux;
                    $aux = $Y[$i];
                    $Y[$i] = $Y[$i+1];
                    $Y[$i+1] = $aux;
                }
            }
        }
        if (($valor<$X[0])or($valor>$X[$n-1])) {
            echo "<br>";
            echo "".$msg->get('SPLINE_MSG_24')."".($valor)."".$msg->get('SPLINE_MSG_25')."[".($X[0]).",".($X[$n-1])."].";
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=lagrange.php>";
            echo "<input type=hidden name=n value=".($n).">";
            echo "<input type=hidden name=opcao_execucao value=".($opcao_execucao).">";
            echo "<input type=hidden name=executar value=sim>";
            for ($i=0; $i<$n; $i++) {
                echo "<input type=hidden name=X[".($i)."] value=".($X[$i]).">";
                echo "<input type=hidden name=Y[".($i)."] value=".($Y[$i]).">";
            } // end for
            echo "<p>";
            echo "<input class=button type=submit name=Submit value=".$msg->get('SPLINE_MSG_26').">";
            echo "<input type=hidden name=distribuicao value=".$distribuicao.">";
            echo "<input type=hidden name=funcao value=\"".$funcao."\">";
            echo "<input type=hidden name=a value=".$a.">";
            echo "<input type=hidden name=b value=".$b.">";
            echo "</form>";
        } else {
            $ne=3*$grau;
            if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo")
                verificaBib($xml_file);
            echo "<br>";
            echo $msg->get('LAGRANGE_MSG_19');
            echo "<br><br><table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#000000\"><tr><td align=\"center\" bgcolor=\"#ffffff\">&Iacute;ndice</td><td align=\"center\" width=\"60\" bgcolor=\"#ffffff\">x</td><td align=\"center\" width=\"60\" bgcolor=\"#ffffff\">y</td></tr>";
            for ($i=0; $i<$n; $i++) {
                echo "<tr>";
                echo "<td align=\"center\" bgcolor=\"#ffffff\">$i</td><td align=\"center\" bgcolor=\"#ffffff\">".round($X[$i],4)."</td><td align=\"center\" bgcolor=\"#ffffff\">".round($Y[$i],4)."</td>";
                echo "</tr>";
            } //for
            echo "</table>";
            echo "<br>";
            echo "".$msg->get('LAGRANGE_MSG_20')."<input type=text size='6' maxlength='8' name=$valor value=".($valor).">";
            echo "<br><br>";
            for ($i=0; $i<=$grau; $i++) {
                $string[$i] =''; // string para gerar o grafico
                $string_tela1[$i] =''; //string para exibir polinmios na tela 1 (com valor desconhecido)
                $string_tela2[$i] =''; //string para exibir polinmios na tela 2 (com valor desconhecido)
                $string_tela3[$i] =''; //string para exibir polinmios na tela 1 (frmula geral)
                $string_tela4[$i] =''; //string para exibir polinmios na tela 2 (frmula geral)
                $l[$i]=1;
                $divisor[$i] =1;
                for($k=0;$k<=$grau;$k++) {
                    if($k!=$i) {
                        //gerar string da funcao
                        if ($X[$k] < 0) {
                            $string[$i].='($x+'.(abs($X[$k])).')*';
                            $string_tela1[$i].='('.$valor.'+'.(abs($X[$k])).')';
                            $string_tela2[$i] .= "(".$X[$i]." + ".(abs($X[$k])).")";
                            $string_tela3[$i].='(x - x<sub>'.$k.'</sub>)';
                            $string_tela4[$i] .= "(x<sub>".$i."</sub> - x<sub>".$k."</sub>)";
                        } else {
                            $string[$i].='($x-'.($X[$k]).')*';
                            $string_tela1[$i].='('.$valor.'-'.($X[$k]).')';
                            $string_tela2[$i] .= "(".$X[$i]." - ".$X[$k].")";
                            $string_tela3[$i].='(x - x<sub>'.$k.'</sub>)';
                            $string_tela4[$i] .= "(x<sub>".$i."</sub> - x<sub>".$k."</sub>)";
                        } //fim das strings
                        $divisor[$i] *= $X[$i]-$X[$k];
                        $l[$i]*= ($valor-$X[$k]) / ($X[$i]-$X[$k]);
                    } // end if k
                }
            }
            $p=0;
            $string2='0';
            for ($i=0;$i<=$grau;$i++) {
                if ($Y[$i]/$divisor[$i] > 0)
                    $string2.="+$string[$i]".($Y[$i]/$divisor[$i])."";
                else
                    $string2.="-$string[$i]".(abs($Y[$i]/$divisor[$i]))."";
                $p+=$l[$i]*$Y[$i];
            }
            // Exibe na tela os resultados
            echo "<b><p align=center> ".$msg->get('Polinomios_Lagrange')." </p></b>";
            echo "<br>";
            echo "<b><p align=center> ".$msg->get('Formula_Geral')." </p></b>";
            echo "<br>";
            for ($i=0; $i<=$grau; $i++) {
                echo "L<sub>".$i."</sub>  = ".$string_tela3[$i]." / ".$string_tela4[$i];
                echo "<br><br>";
            }
            echo "<b>".$msg->get('NEWTON_MSG_26')."</b>";
            echo "<br><br>";
            echo "P(x) = ";
            for ($i=0; $i<=$grau; $i++)
                echo "y<sub>".$i."</sub> * L<sub>".$i."</sub>(x)".(($i == $grau)?"":" + ");
            echo "<br><br>";
    
            /********** experimental ************/
            echo "P(x) = ";
            for ($i=0; $i<=$grau; $i++)
                echo round($Y[$i],4)." * L<sub>".$i."</sub>(x)".(($i == $grau)?"":" + ");
            echo "<br><br>";
            echo "P(x) = ";
            for ($i=0; $i<=$grau; $i++)
            {
                $troca1[$i] = "x<sub>".$i."</sub>";
                $troca2[$i] = $X[$i];
            }
            for ($i=0; $i<=$grau; $i++)
                echo round($Y[$i],4)." * [".str_replace($troca1,$troca2,$string_tela3[$i])." / ".str_replace($troca1,$troca2,$string_tela4[$i])."]".(($i == $grau)?"":" + ");
            echo "<br><br>";
            /************************************/
    
            echo "<b><p align=center>".$msg->get("Formula_Aplicada_Ponto")." ".$valor."</p></b>";
            echo "<br>";
            for ($i=0; $i<=$grau; $i++) {
                echo "L<sub>".$i."</sub>  = ".$string_tela1[$i]." / ".$string_tela2[$i]." = ".$l[$i];
                echo "<br><br>";
            }
            echo "<b>".$msg->get('Polinomio_Avaliado_Ponto')." $valor:</b>";
            echo "<br><br>";
            echo "P(x) = ";
            for ($i=0; $i<$grau; $i++) {
                echo $Y[$i]." * ".$l[$i]." + ";
            }
            echo $Y[$grau]." * ".$l[$grau]." = ".$p;
    
            // para gerar o grafico dos pontos
            $dados_grafico = "Lagrange|";
            $dados_grafico .= "$string2|";
            $dados_grafico .= "".($n+1)."|";
            for ($i=0;$i<$n;$i++)  $dados_grafico .= "$X[$i]|";
            $dados_grafico .= "$valor|";
            for ($i=0;$i<$n;$i++)  $dados_grafico .= "$Y[$i]|";
            $dados_grafico .= "$p|";
            $dados_grafico .= "$idioma|";
            if ($opcao_execucao == 1) $dados_grafico .= ":$funcao:|";
            $arquivo = gera_nome_arquivo();
            $conn = &ADONewConnection($A_DB_TYPE);
            $conn->PConnect($A_DB_HOST,$A_DB_USER,$A_DB_PASS,$A_DB_DB);
            // $conn->debug=1;
            $sql = "INSERT INTO grafico(id,dados) values ('".$arquivo."','".$dados_grafico."');";
            $rs = $conn->Execute($sql);
            if ($rs === false) die(A_LANG_LOGIN_MSG5);
            $rs->Close();
            echo "<br><br>";
            echo "<b>".$msg->get('LAGRANGE_MSG_22')."</b> <br>";
            echo "<font size=4>p</font>(".($valor).") = ".($p)."<p><p>";
            echo "<table>";
            echo "<tr>";
            echo "<td><img src=interpolacao_grafico.php?arquivo=".$arquivo."  border=0 align=left width=600 height= 400></td>";
            echo "</table>";
            echo "<br>";
            // formulario para efetuar o calculo para outro ponto
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=lagrange.php>";
            echo "<input type=hidden name=n value=".($n).">";
            if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim")
            {
                echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
                echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">";
                echo "<input type=\"hidden\" name=\"navegacao\" value=\"sim\">";
            }
            echo "<input type=hidden name=opcao_execucao value=".($opcao_execucao).">";
            echo "<input type=hidden name=executar value=sim>";
            for ($i=0; $i<$n; $i++) {
                echo "<input type=hidden name=X[".($i)."] value=".($X[$i]).">";
                echo "<input type=hidden name=Y[".($i)."] value=".($Y[$i]).">";
            } // end for
            echo "<input class=button type=submit name=Submit value=".$msg->get('SPLINE_MSG_26').">";
            if (isset($distribuicao)) echo "<input type=hidden name=distribuicao value=".$distribuicao.">";
            if (isset($funcao)) echo "<input type=hidden name=funcao value=\"".$funcao."\">";
            if (isset($a)) echo "<input type=hidden name=a value=".$a.">";
            if (isset($b)) echo "<input type=hidden name=b value=".$b.">";
            echo "</form>";
            echo "<br>";
            echo $msg->get('G_PROXIMO_EXEMPLO');
            echo "<br><br>";
            // formulario para efetuar o mesmo calculo pelo metodo de newton
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=newton.php>";
            if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim")
            {
                echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
                echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">";
                echo "<input type=\"hidden\" name=\"navegacao\" value=\"sim\">";
            }
            echo "<input type=hidden name=n value=".($n).">";
            echo "<input type=hidden name=opcao_execucao value=".($opcao_execucao).">";
            echo "<input type=hidden name=executar value=sim>";
            for ($i=0; $i<$n; $i++) {
                echo "<input type=hidden name=X[".($i)."] value=".($X[$i]).">";
                echo "<input type=hidden name=Y[".($i)."] value=".($Y[$i]).">";
            } // end for
            if (isset($distribuicao)) echo "<input type=hidden name=distribuicao value=".$distribuicao.">";
            if (isset($funcao)) echo "<input type=hidden name=funcao value=\"".$funcao."\">";
            if (isset($a)) echo "<input type=hidden name=a value=".$a.">";
            if (isset($b)) echo "<input type=hidden name=b value=".$b.">";
            echo "<input type=hidden name=valor value=".$valor.">";
            echo "<input class=button type=submit name=Calcular value='".$msg->get('NEWTON_MSG_03')."'>";
            echo "</form>";
            // formulario para efetuar o mesmo calculo pelo metodo de splines
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=spline.php>";
            if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim")
            {
                echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
                echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">";
                echo "<input type=\"hidden\" name=\"navegacao\" value=\"sim\">";
            }
            echo "<input type=hidden name=n value=".($n).">";
            echo "<input type=hidden name=opcao_execucao value=".($opcao_execucao).">";
            echo "<input type=hidden name=executar value=sim>";
            for ($i=0; $i<$n; $i++) {
                echo "<input type=hidden name=x[".($i)."] value=".($X[$i]).">";
                echo "<input type=hidden name=y[".($i)."] value=".($Y[$i]).">";
            } // end for
            echo "<input class=button type=submit name=Calcular value='".$msg->get('SPLINE_MSG_03')."'>";
            if (isset($distribuicao)) echo "<input type=hidden name=distribuicao value=".$distribuicao.">";
            if (isset($funcao)) echo "<input type=hidden name=funcao value=\"".$funcao."\">";
            if (isset($a)) echo "<input type=hidden name=a value=".$a.">";
            if (isset($b)) echo "<input type=hidden name=b value=".$b.">";
            echo "<input type=hidden name=valor value=".$valor.">";
            echo "</form>";
            echo "<p>";
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=lagrange.php>";
            echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
            echo "</form>";
            if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim")
            {
                echo "<form name=\"exemplos\" enctype=\"multipart/form-data\" method=\"post\">";
                echo "<script language=\"javascript\" type=\"text/javascript\">\n";
                echo "function criarLinks(value) {\n";
                echo "document.exemplos.indice.value = value;\n";
                echo "document.exemplos.action = 'index.php?inc=lagrange.php&modo=exemplo'\n";
                echo "document.exemplos.submit();\n";
                echo "}\n";
                echo "</script>";
                echo "<input type=\"hidden\" name=\"id_bib\" value=\"".@$id_bib."\">";
                echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
                echo "<input type=\"hidden\" name=\"indice\">";
                echo "</form>";
                echo $msg->get('Outros_Exemplos')."<br>";
                $objeto = new DomDocument();
                $objeto->load($xml_file);
                $filho = $objeto->getelementsbytagname("interpolation");
                if ($filho->length > 0)
                {
                    $interpol = $filho->item(0)->getelementsbytagname("interpol");
                    for ($i=0; $i<$interpol->length; $i++)
                    {
                        if ($i != 0) echo " | ";
                        if ($i == $indice) echo "<b>";
                        echo "<a href=\"javascript:criarLinks($i);\"><u>".($i+1)."</u></a>";
                        if ($i == $indice) echo "</b>";
                    }
                }
            }
        }
    }
}
?>
</div>